package cn.edu.sasu.controller;

import cn.edu.sasu.common.annotation.RoleNum;
import cn.edu.sasu.common.base.LayuiRespResult;
import cn.edu.sasu.common.base.RespResult;
import cn.edu.sasu.common.constants.Role;
import cn.edu.sasu.domain.dto.SysUserSaveDTO;
import cn.edu.sasu.domain.dto.UpdatePasswordDTO;
import cn.edu.sasu.domain.vo.SysUserInfoVO;
import cn.edu.sasu.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sys_user")
public class SysUserController {

     @Autowired
     private SysUserService sysUserService;

     // 修改密码
     @RoleNum(Role.COMMON)
     @PostMapping("/updatePassword")
     public RespResult updatePassword(@RequestBody @Validated UpdatePasswordDTO updatePasswordDTO){
          return sysUserService.updatePassword(updatePasswordDTO);
     }


     @RoleNum(Role.ADMIN)
     @PostMapping("/updateInfo")
     public RespResult updateInfo(@RequestBody SysUserInfoVO sysUserInfoVO){
          return sysUserService.updateInfo(sysUserInfoVO);
     }

     // 查询系统用户信息
     @RoleNum(Role.COMMON)
     @GetMapping("/findSysUserAll")
     public LayuiRespResult findSysUserAll(Integer page,Integer limit){
          return sysUserService.findSysUserAll(page,limit);
     }

     // 删除
     @RoleNum(Role.ADMIN)
     @PostMapping("/del")
     public RespResult del(Integer userId){
          return sysUserService.delSysUserByUserId(userId);
     }

     // 批量删除
     @RoleNum(Role.ADMIN)
     @PostMapping("/batchdel")
     public RespResult batchdel(Integer[] userIds){
          return sysUserService.batchdel(userIds);
     }

     // 搜索
     @RoleNum(Role.ADMIN)
     @GetMapping("/search")
     public LayuiRespResult search(Integer page,Integer limit,String username){
          return sysUserService.search(page,limit,username);
     }

      /*管理员添加用户*/
     @RoleNum(Role.ADMIN)
     @PostMapping("/save")
     public RespResult save(@RequestBody @Validated SysUserSaveDTO sysUserSaveDTO){
          return sysUserService.save(sysUserSaveDTO);
     }


}
